package com.zood.controller;

import com.zood.controller.utils.R;
import com.zood.domain.model;
import com.zood.service.modelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/model")
public class modelController {
    @Autowired
    private modelService models;

    @PostMapping
    public R save(@RequestBody model stone) throws IOException {
        boolean flag = models.save(stone);
        return new R(flag, flag ? "添加成功^_^" : "添加失败-_-!");
    }

    @PutMapping
    public R update(@RequestBody model stone) throws IOException {
        boolean flag = models.modify(stone);
        return new R(flag, flag ? "修改成功^_^" : "修改失败-_-!");
    }

    @DeleteMapping("{mid}/{tid}")
    public R delete(@PathVariable Integer mid,@PathVariable Integer tid){
        return new R(models.delete(mid,tid));
    }

    @GetMapping
    public R getAll(){
        return new R(true, models.mtshow());
    }
}
